package cn.gdcp.recycleviewtest;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;

public class EditActivity extends AppCompatActivity {
    EditText addName;
    EditText addAge;
    RadioButton m1;
    RadioButton m2;
    RadioButton m3;
    String name;
    String age;
    int imageId;
    Button summitBtn;
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_edit);
        initAddView();
        summitBtn.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                name=addName.getText().toString();
                age=addAge.getText().toString();
                if (m1.isChecked()){
                    imageId=R.drawable.m1;
                }else if (m2.isChecked()){
                    imageId=R.drawable.m2;
                }else {
                    imageId=R.drawable.m3;
                }
                ReturnMessage(name,age,imageId);
            }
        });
    }

    private void ReturnMessage(String name, String age, int imageId) {
        Intent intent=new Intent();
        intent.putExtra("NAME",name);
        intent.putExtra("AGE",age);
        intent.putExtra("IMAGEID",imageId);
        setResult(2002,intent);
        finish();
    }


    private void initAddView() {
        addName=findViewById(R.id.edit_name);
        addAge=findViewById(R.id.edit_age);
        summitBtn=findViewById(R.id.summit_edit_button);
        m1=findViewById(R.id.edit_m1);
        m2=findViewById(R.id.edit_m2);
        m3=findViewById(R.id.edit_m3);
    }
}
